// 定义聊天消息接口
export interface ChatMessage {
  id: string
  role: 'user' | 'assistant'
  content: string
  timestamp: number
  resources?: Array<RetrieverResource>
}

// 定义配置接口
export interface ChatConfig {
  apiKey: string
  dataset_Key: string
  userId: string
}

// 用量信息
export interface Usage {
  prompt_tokens: number;
  completion_tokens: number;
  total_tokens: number;
}

// 参考资源
export interface RetrieverResource {
  position: number,
  dataset_id: string,
  dataset_name: string,
  document_id: string,
  document_name: string,
  segment_id: string,
  score: number,
  content: string
}

// 基础事件接口
export interface BaseEvent {
  event: string;
  task_id: string;
  message_id: string;
}

// 消息事件
export interface MessageEvent extends BaseEvent {
  event: 'message';
  answer: string;
  created_at: number;
}

// 消息结束事件
export interface MessageEndEvent extends BaseEvent {
  event: 'message_end';
  metadata: {
    usage: Usage;
    retriever_resources?: RetrieverResource[];
  };
}

// 语音合成事件
export interface TtsMessageEvent extends BaseEvent {
  event: 'tts_message';
  audio: string; // Base64编码的音频数据
}

// 语音合成结束事件
export interface TtsMessageEndEvent extends BaseEvent {
  event: 'tts_message_end';
}

// 消息替换事件
export interface MessageReplaceEvent extends BaseEvent {
  event: 'message_replace';
  answer: string;
}

// 错误事件
export interface ErrorEvent extends BaseEvent {
  event: 'error';
  message: string;
}

// 心跳事件
export interface PingEvent {
  event: 'ping';
}

// 所有可能的事件类型联合
export type ChatEvent = 
  | MessageEvent 
  | MessageEndEvent 
  | TtsMessageEvent 
  | TtsMessageEndEvent 
  | MessageReplaceEvent 
  | ErrorEvent 
  | PingEvent; 